package com.aop.demo.test;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class TicketSeller {
    static Queue<String> tickets = new ConcurrentLinkedQueue();

    static {
        for (int i = 1; i <= 100; i++) {
            tickets.add(i + "");
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                while (true) {
                    String s = tickets.poll();
                    if (s == null) {
                        break;
                    } else {
                        System.out.println("正在出售第" + s + "张票！");
                    }
                }
            }, "窗口" + i).start();
        }
    }

 /*   public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        String s = tickets.poll();
                        if (s == null) {
                            break;
                        } else {
                            System.out.println("正在出售第" + s + "张票！");
                        }
                    }
                }
            }, "窗口" + i ).start();
        }
    }*/
}
